package ru.amse.tsyganov.jumleditor.view;

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;

import ru.amse.tsyganov.jumleditor.model.State;
import ru.amse.tsyganov.jumleditor.model.StateVertex;
import ru.amse.tsyganov.jumleditor.model.Transition;

public abstract class StateView<T extends State> extends View<T> {
	private final StateVertex<TransitionView<Transition>, StateView<? extends State>> stateVertex = 
		new StateVertex<TransitionView<Transition>, StateView<? extends State>>(this);
	
	private int x;
	private int y;
	private int width = 90;
	private int height = 60;
	
	public abstract void paint(GC gc);
	
	public int getX() {
		return x;
	}
	
	public void setX(int x) {
		this.x = x;
	}
	
	public int getY() {
		return y;
	}
	
	public void setY(int y) {
		this.y = y;
	}
	
	public int getWidth() {
		return width;
	}
	
	public void setWidth(int newWidth) {
		if (newWidth < 0) {
			throw new IllegalArgumentException();
		}
		
		this.width = newWidth;
	}
	
	public int getHeight() {
		return height;
	}
	
	public void setHeight(int newHeight) {
		if (newHeight < 0) {
			throw new IllegalArgumentException();
		}
		
		this.height = newHeight;
	}
	
	public int getCenterX() {
		return getX() + getWidth()/2;
	}
	
	public int getCenterY() {
		return getY() + getHeight()/2;
	}
	
	public Rectangle getRectangle() {
		return new Rectangle(x, y, width, height);
	}
	
	public StateVertex<TransitionView<Transition>, StateView<? extends State>> getStateVertex() {
		return stateVertex;
	}
}
